<template>
	<view>
		<!-- 地址 -->
		<view @click="addressManagement" class="address-section">
			<view class="order-content">
				<!-- <text class="yticon icon-shouhuodizhi"></text> -->
				<image src="../../static/dizhi.png" class="icon-dizhis"></image>
				<view class="cen" v-if="addressData.address">
					<view class="top">
						<text class="name">{{addressData.name}}</text>
						<text class="mobile">{{addressData.mobile}}</text>
					</view>
					<text class="address">{{addressData.address}} {{addressData.area}}</text>
				</view>
				<view class="cen" v-else>
					<text class="address">请选择收货地址</text>
				</view>
				<text class="yticon icon-you"></text>
			</view>
		</view>
		
		<view class="goods-section">
			<!-- 商品列表 -->
			<view class="g-item" v-for="(item,index) in couponLists" :key="index">
				<image :src="item.cover_pic"></image>
				<view class="right">
					<text class="title clamp">{{item.name}}</text>
					<text class="spec">{{item.attr}}</text>
					<view class="price-box">
						<view class="price-boxs">
							<text class="numbers">￥</text>
							<text class="price">{{item.price}}</text>
						</view>
						<text class="number">×{{num}}</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 优惠明细 -->
		<view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp orderNotes">订单备注</text>
				<view class="cell-tit message">
					<input class="cell-tit textArea" type="text" placeholder="给商家留言,选填" placeholder-style="font-size:26rpx" value="" maxlength="100" v-model="numbers" @input="leaveMessage" />
					<view class="cell-tit nums">
						<text>{{entered}}</text><text>/100</text>
					</view>
				</view>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">商品总额</text>
				<view class="cell-tit totalPrice">
					<text class="cell-tip symbol">￥</text>
					<text class="cell-tip">{{goodsAll}}</text>
				</view>
			</view>
			<view class="yt-list-cell b-b">
				<view class="cell-tit clamp freight" @click="freightDescription('showfreight')">
					<view class="waring">运费</view>
					<!-- <view><icon class="icon-box-img" type="warn" color="#f2a675" size="14"></icon></view> -->
				</view>
				<text class="cell-tip active">包邮</text>
			</view>
			
			<view class="yt-list-cell b-b" @click="toggleMask('show')">
				<text class="cell-tit clamp">微信优惠</text>
				<view class="cell-tit flex">
					<text class="cell-tip active">
						-￥20.00
					</text>
					<text class="cell-more wanjia wanjia-gengduo-d"></text>
					<text class="yticon icon-you iconRight"></text>
				</view>
			</view>
		</view>
		
		<!-- 底部 -->
		<view class="footer">
			<view class="price-content" @click="discountDetails('shows')">
				<view class="price-content-top">
					<text>合计:</text>
					<text class="price-tip">￥</text>
					<text class="price">{{sum}}</text>
					<icon class="icon-box-img" type="warn" color="#f2a675" size="9"></icon>
					<text class="discountDetails">优惠明细</text>
				</view>
				<view class="price-content-bottom">
					<text>已优惠:</text>
					<text>20.00</text>
					<text class="payPrice">以实际支付金额为准</text>
				</view>
			</view>
			<text class="submit" @click="submit">提交订单</text>
		</view>
		
		<!-- 优惠明细 -->
		<view class="masks" :class="maskStates===0 ? 'none' : maskStates===1 ? 'show' : ''" @click="discountDetails">
			<view class="discountDetail" @click.stop.prevent="stopPrevent">
				<view class="discountDetail-header">
					<text>优惠明细</text>
					<text class="receive-chas" @click="closeDetail">×</text>
				</view>
				<view class="discountDetail-flex">
					<text>商品总额</text>
					<text>￥{{goodsAll}}</text>
				</view>
				<view class="discountDetail-flex">
					<text>运费</text>
					<text>￥0.00</text>
				</view>
				<view class="discountDetail-line"></view>
				<view class="discountDetail-wx">微信优惠</view>
				<view class="discountDetail-flex six">
					<text class="huiColor">满39减20</text>
					<text>-￥20</text>
				</view>
				<view class="discountDetail-line"></view>
				<view class="discountDetail-flex">
					<text>优惠总额</text>
					<text class="redColor">-￥20.00</text>
				</view>
				<view class="discountDetail-flex totals">
					<text>合计</text>
					<view>
						<text class="huiColor font-er">以实际支付金额为准</text>
						<text> ￥219.80</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 优惠券面板 -->
		<view class="mask" :class="maskState===0 ? 'none' : maskState===1 ? 'show' : ''" @click="toggleMask">
			<view class="mask-content" @click.stop.prevent="stopPrevent">
				<!-- 优惠券页面，仿mt -->
				<view class="receive">
					<text>领取微信优惠券</text>
					<text class="receive-cha" @click="discountDetail">×</text>
				</view>
				<view class="coupon-counts">
					<view class="coupon-item" v-for="(item,index) in couponList" :key="index">
						<view class="con">
							<view class="left">
								<text class="title">{{item.title}}</text>
								<text class="times">满199减110</text>
								<text class="time">2020-04-27-2020.05.31</text>
							</view>
							<view class="dashed"></view>
							<view class="right" :data-count="index" @click="imReceive">{{item.content}}</view>
							<view class="circle l"></view>
							<view class="circle r"></view>
						</view>
						<text class="tips">微信支付</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 运费说明面板 -->
		<view class="panel" :class="maskStatus===0 ? 'nonefreight' : maskStatus===1 ? 'showfreight' : ''" @click="freightDescription">
			<view class="panel-content" @click.stop.prevent="stopPrevent">
				<!-- 优惠券页面，仿mt -->
				<view class="panels">
					<text>运费说明</text>
					<text class="panel-cha" @click="closeFreight">×</text>
				</view>
				<view>
					<view class="panel-item">全国大部分地区按照基础邮费执行，部分偏远地区和活动商品邮费有所不同，具体以实际结算金额为准</view>
					<view class="panel-lines"></view>
					<view class="panel-know" @click="closeFreight">知道了</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import url from '../../components/hosturl.js';
	export default {
		data() {
			return {
				goodsAll:0,  //商品总额
				sum:100,  //合计
				numbers:'', //剩余数字
				entered: 0, //留言已输入数字
				maskState: 0, //优惠券面板显示状态
				maskStates: 0, //优惠明细面板显示状态
				maskStatus: 0,//运费说明显示
				desc: '', //备注
				payType: 1, //1微信 2支付宝
				couponList: [
					{
						title: '50',
						price: 5,
						content:'立即领取'
					},
					{
						title: '110',
						price: 10,
						content:'立即领取'
					},
					{
						title: '20',
						price: 15,
						content:'立即领取'
					},
					{
						title: '20',
						price: 15,
						content:'立即领取'
					},
					{
						title: '20',
						price: 15,
						content:'立即领取'
					}
				],
				couponLists: [
					// {
					// 	cover_pic: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1620020012,789258862&fm=26&gp=0.jpg',
					// 	name:'古黛妃 短袖t恤女夏装2019新款',
					// 	norms:'春装款 L',
					// 	price: 35,
					// 	num:'1'
					// },
					// {
					// 	cover_pic: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1620020012,789258862&fm=26&gp=0.jpg',
					// 	name:'古黛妃 短袖t恤女夏装2019新款',
					// 	norms:'春装款 L',
					// 	price: 35,
					// 	num:'1'
					// },
					// {
					// 	cover_pic: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1620020012,789258862&fm=26&gp=0.jpg',
					// 	name:'古黛妃 短袖t恤女夏装2019新款',
					// 	norms:'春装款 L',
					// 	price: 35,
					// 	num:'1'
					// }
				],
				addressData: {
					name: '许小星',
					mobile: '13853989563',
					addressName: '金九大道',
					address: '山东省济南市历城区',
					area: '149号',
					default: false,
				},
				num:0
			}
		},
		onLoad(option){
			//首页立即购买
			
			/*
			
			var arr = [];
			arr.push(datas);
			this.couponLists = arr;
			var cheng = arr[0].price*arr[0].num;
			this.goodsAll = cheng;
			this.sum = cheng;
			*/
		   var datas = JSON.parse(decodeURIComponent(option.obj));
		   
		   var num = datas.num;
		   var token=uni.getStorageSync('token');
		   var sid= datas.id;
		   var price= datas.price;
		   var attr= datas.attr;
		   
		   uni.request({
		   	url:url+'/wechatApi/DirectAnOrder',
		   	method:'POST',
		   	data:{
		   		token,
		   		sid,
		   		num,
		   		attr,
		   		price
		   	},
		   	header: {
		   	    "Content-Type": "application/x-www-form-urlencoded"
		   	},
		   	success:res=>{
				console.log('提交效果',res.data);
				this.addressData = res.data.address;
				this.goodsAll = res.data.price;
				this.couponLists.push(res.data.commodity);
				this.num = res.data.num;
			}
		   })
			
			
			//调取购物车接口
			// uni.request({
			// 	url:url+'/Shopping/getShoppingCar',
			// 	data:{ 
			// 		'token':uni.getStorageSync('token')
			// 	},
			// 	success:(res)=>{
			// 		this.couponLists = res.data.message;
			// 		console.log("1",res.data.message);
			// 	}
			// });
			
		},
		methods: {
			//跳转地址管理
			addressManagement(){
				wx.redirectTo({
				  url: '/pages/user/address?source=1'
				});
			},
			//显示运费说明面板
			freightDescription(typ){
				let timer = typ === 'showfreight' ? 10 : 300;
				let	statu = typ === 'showfreight' ? 1 : 0;
				this.maskStatus = 2;
				setTimeout(()=>{
					this.maskStatus = statu;
				}, timer);
			},
			//领取优惠券
			imReceive(e){
				if(this.couponList[e.currentTarget.dataset.count].content == '立即领取') {
					this.couponList[e.currentTarget.dataset.count].content = '已领取';
					wx.showToast({
						title: '领取成功',
					});
				}else{
					wx.showToast({
						title: '卷已在卡包中',
					});
				}
			},
			//关闭运费说明
			closeFreight(){
				this.maskStatus = 0;
			},
			//关闭优惠券
			discountDetail(){
				this.maskState = 0;
			},
			//关闭优惠明细
			closeDetail(){
				this.maskStates = 0;
			},
			//显示留言剩余数字
			leaveMessage(){
				let txtVal = this.numbers.length;
				this.entered = txtVal;
			},
			//显示优惠明细面板
			discountDetails(types){
				let timers = types === 'shows' ? 10 : 300;
				let	states = types === 'shows' ? 1 : 0;
				this.maskStates = 2;
				setTimeout(()=>{
					this.maskStates = states;
				}, timers);
				console.log('优惠明细');
			},
			//显示优惠券面板
			toggleMask(type){
				let timer = type === 'show' ? 10 : 300;
				let	state = type === 'show' ? 1 : 0;
				this.maskState = 2;
				setTimeout(()=>{
					this.maskState = state;
				}, timer);
			},
			numberChange(data) {
				this.number = data.number;
			},
			changePayType(type){
				this.payType = type;
			},
			submit(){
				uni.redirectTo({
					url: '/pages/shoppingcart/pay?price='+this.sum
				})
			},
			stopPrevent(){}
		}
	}
</script>

<style lang="scss">
	page { background: $page-color-base;background-color: #f7f7f7;padding-bottom: 100upx; }
	.icon-dizhis { height: 40rpx;width: 40rpx;margin: 0 10rpx 0 30rpx; }
	//运费说明模板
	.panel{ align-items: flex-end;background: rgba(0,0,0,0);bottom: 0;display: flex;left: 0;padding: 0 90rpx;position: fixed;top: var(--window-top);width: 100%;z-index: 9995;
		.panel-content{ background: #fff;border-radius: 20rpx;bottom: 33%;height: 450rpx;width: 100%;overflow-y:scroll;padding: 48rpx 26rpx 0 26rpx;position: relative;z-index: 10000;}
		&.nonefreight{ display: none; }
		&.showfreight{ background: rgba(0,0,0,.4);
			.panel-content{ transform: translateY(0); }
		}
	}
	.panels { font-size: 32rpx;position: relative;text-align: center; }
	.panel-cha { color: #999;font-size: 50rpx;position: absolute;right: 0;top: -30rpx; }
	.panel-item { color: #666;font-size: 28rpx;letter-spacing: 3rpx;line-height: 40rpx;margin: 30rpx 0 40rpx 0; }
	.panel-lines { border-top: 1px #ddd solid;width: 100%; }
	.panel-know { background: #d73037;border-radius: 50rpx;color: #fff;font-size: 32rpx;height: 80rpx;line-height: 80rpx;margin: 40rpx 0 0 20rpx;text-align: center;width: 476rpx; }
	.address-section { padding-top: 24rpx;position: relative;
		.order-content { align-items: center;background: #fff;border-radius: 20rpx;display: flex;margin: 0 24rpx;padding: 24rpx 0; }
		.icon-shouhuodizhi { align-items: center;color: #888;display: flex;flex-shrink: 0;font-size: 44upx;justify-content: center;width: 90upx; }
		.cen { color: $font-color-dark;display: flex;flex: 1;flex-direction: column;font-size: 28upx; }
		.name { font-size: 28rpx;margin-right: 24upx; }
		.address { color: $font-color-light;font-size: 24rpx;margin-right: 20upx;margin-top: 16upx; }
		.icon-you { color: $font-color-light;font-size: 32upx;margin-right: 30upx; }
		.a-bg { bottom: 0;display: block;height: 5upx;left: 0;position: absolute;width: 100%; }
	}
	.goods-section .g-item:nth-last-child(1) { border-bottom: none;padding-bottom: 0; }
	.price-box { display: flex; }
	.price-box .numbers { color: $base-color;font-size: 20rpx; }
	.goods-section { background: #fff;border-radius: 20rpx;margin: 24rpx;padding: 1px 0;
		.g-header { align-items: center;display: flex;height: 84upx;padding: 0 30upx;position: relative; }
		.logo { border-radius: 100px;display: block;height: 50upx;width: 50upx; }
		.name { color: $font-color-base;font-size: 30upx;margin-left: 24upx; }
		.g-item { border-bottom: 1px #ddd dashed;display: flex;margin: 20upx 30upx;padding-bottom: 20rpx;
			image { border-radius: 4upx;display: block;height: 140upx;flex-shrink: 0;width: 140upx; }
			.right { flex: 1;overflow: hidden;padding-left: 24upx; }
			.title { color: $font-color-dark;font-size: 28rpx; }
			.spec { color: $font-color-light;font-size: 24rpx; }
			.price-box { align-items: center;color: $font-color-dark;display: flex;font-size: 26rpx;justify-content: space-between;padding-top: 10upx;
				.price { color: $base-color;font-size: 28rpx;margin-bottom: 4upx; }
				.number{ color: #9e9e9e;font-size: 20rpx;margin-left: 20upx; }
			}
			.step-box { position: relative; }
		}
	}
	.yt-list { background: #fff;border-radius: 20rpx;margin: 20rpx 24rpx 100rpx 24rpx; }
	.yt-list-cell { align-items: center;display: flex;justify-content: space-between;align-items: baseline;line-height: 70upx;padding: 10upx 50upx 10upx 40upx;position: relative;
		&.cell-hover { background: #fafafa; }
		&.b-b:after { left: 30upx; }
		.cell-icon { background: #f85e52;border-radius: 4upx;color: #fff;font-size: 22upx;height: 32upx;line-height: 32upx;margin-right: 12upx;text-align: center;width: 32upx;
			&.hb { background: #ffaa0e; }
			&.lpk { background: #3ab54a; }
		}
		.cell-more { align-self: center;color: $font-color-light;font-size: 24upx;margin-left: 8upx;margin-right: -10upx; }
		.cell-tit { color: $font-color-light;font-size: 26rpx; }
		.cell-tip { color: $font-color-dark;font-size: 26upx;
			&.disabled { color: $font-color-light; }
			&.active { color: $base-color; }
			&.red{ color: $base-color; }
		}
		&.desc-cell { .cell-tit { max-width: 90upx; } }
		.desc { color: $font-color-dark;flex: 1;font-size: $font-base; }
	}
	.b-b:after,.b-t:after { border-bottom: none; }
	.yt-list-cell .message { color: #333;font-size: 22rpx;position: relative;width: 75%; }
	.yt-list-cell .textArea { text-align: right;width: 100%;height: 70rpx;line-height: 70rpx; }
	.yt-list-cell .nums { color: #cdcdcd;font-size: 26rpx;position: absolute;right: 0;top: 30rpx; }
	.yt-list-cell .totalPrice { align-items: baseline;color: #333;display: flex;font-size: 22rpx; }
	.yt-list-cell .symbol { font-size: 20rpx; }
	.yt-list-cell .flex { display: flex;position: relative; }
	.yt-list-cell .iconRight { position: absolute;right: -40rpx;top: 0; }
	.discountDetails { font-size: 22rpx;margin-left: 5rpx; }
	/* 支付列表 */
	.pay-list{ background: #fff;margin-top: 16upx;padding-left: 40upx;
		.pay-item{ align-items: center;display: flex;height: 110upx;line-height: 1;padding-right: 20upx;position: relative; }
		.icon-weixinzhifu{ color: #6BCC03;font-size: 40upx;width: 80upx; }
		.icon-alipay{ color: #06B4FD;font-size: 40upx;width: 80upx; }
		.icon-xuanzhong2{align-items: center;color: $base-color;display: flex;font-size: 40upx;height: 60upx;justify-content: center;width: 60upx; }
		.tit{ color: $font-color-dark;flex: 1;font-size: 32upx; }
	}
	.footer{ align-items: center;background-color: #fff;bottom: 0;box-shadow: 0 -1px 5px rgba(0,0,0,.1);color: $font-color-base;display: flex;font-size: 24rpx;height: 110rpx;justify-content: space-between;left: 0;position: fixed;width: 100%;z-index: 998;
		.price-content{ padding-left: 30upx; }
		.price-tip{ color: $base-color;font-size: 20rpx;margin-left: 8upx; }
		.price{ color: $base-color;font-size: 28rpx;margin-right: 40rpx; }
		.submit{ align-items:center;background: #a387eb;border-radius: 50rpx;color: #fff;display:flex;font-size: 32rpx;height: 76rpx;justify-content: center;margin-right: 30rpx;width: 206rpx; }
	}
	.price-content { display: flex;flex-direction: column;justify-content: center; }
	.price-content-top { align-items: baseline;display: flex; }
	.price-content-bottom { color: #666;font-size: 20rpx; }
	.price-content-bottom .payPrice { color: #999;margin-left: 20rpx; }
	.yt-list-cell .freight { display: flex;justify-content: center; }
	.yt-list-cell .waring {
		padding-right: 36rpx;background: url(../../static/warning.png) no-repeat;background-size: 26rpx 26rpx;background-position: 60rpx center;
	}
	.yt-list-cell .icon-box-img { margin: 18rpx 0 0 10rpx; }
	/* 优惠明细面板 */
	.masks{ align-items: flex-end;background: rgba(0,0,0,0);bottom: 0;display: flex;left: 0;position: fixed;transition: .3s;top: var(--window-top);width: 100%;z-index: 9995;
		.discountDetail{ background: #fff;border-top-left-radius: 20rpx;border-top-right-radius: 20rpx;max-height: 70vh;min-height: 30vh;overflow-y:scroll;padding: 0 26rpx;position: relative;transition: .3s;width: 100%;z-index: 10000; }
		&.none{ display: none; }
		&.show{ background: rgba(0,0,0,.4);
			.masks-content{ transform: translateY(0); }
		}
	}
	.discountDetail-header { font-size: 32rpx;height: 106rpx;line-height: 106rpx;position: relative;text-align: center; }
	.discountDetail .discountDetail-flex { display: flex;font-size: 28rpx;justify-content: space-between;margin-bottom: 15rpx; }
	.discountDetail-line { border-top: 1px #ddd solid;margin: 32rpx 0; }
	.discountDetail-wx { font-size: 28rpx;margin-bottom: 10rpx; }
	.discountDetail-flex .huiColor { color: #999; }
	.discountDetail .six { font-size: 26rpx; }
	.discountDetail .redColor { color: #d81111; }
	.discountDetail .totals { font-size: 32rpx;margin-top: 20rpx; }
	.discountDetail .font-er { font-size: 22rpx; }
	.receive-chas { font-size: 36rpx;position: absolute;right: 0;top: 0; }
	/* 优惠券面板 */
	.mask{ align-items: flex-end;background: rgba(0,0,0,0);bottom: 0;display: flex;left: 0;position: fixed;transition: .3s;top: var(--window-top);width: 100%;z-index: 9995;
		.mask-content{ background: #f3f3f3;border-top-left-radius: 20rpx;border-top-right-radius: 20rpx;height: 60vh;transform: translateY(100%);transition: .3s;width: 100%; }
		&.none{ display: none; }
		&.show{ background: rgba(0,0,0,.4);	
			.mask-content{ transform: translateY(0); }
		}
	}
	.receive { background: #fff;color: #0b0b0b;font-size: 32rpx;height: 106rpx;left: 0;line-height: 106rpx;position: absolute;text-align: center;top: 0;width: 100%; }
	.receive-cha { font-size: 36rpx;position: absolute;right: 30rpx;top: 0; }
	.coupon-counts { height: 100%;margin-top: 106rpx;overflow-y: scroll; }
	/* 优惠券列表 */
	.coupon-counts .coupon-item:nth-last-child(1){ margin-bottom: 120rpx; }
	.coupon-item{ background: #fff;color: #fff;display: flex;flex-direction: column;margin: 20upx 24upx;
		.con{ align-items: center;background: #a387eb;display: flex;height: 160rpx;padding: 0 30upx;position: relative;
			&:after{ border-bottom: 1px dashed #f3f3f3;bottom: 0;content: '';height: 0;left: 0;position: absolute;transform: scaleY(50%);width: 100%; }
		}
		.left{ display: flex;flex: 1;flex-direction: column;height: 100upx;justify-content: center;overflow: hidden; }
		.title{ font-size: 32rpx;margin-bottom: 10upx;
			&:before{ content: '￥';font-size: 22rpx; }
		}
		.time{ font-size: 18rpx; }
		.times{ font-size: 24rpx; }
		.right{ font-size: 28rpx;padding-left: 30rpx;text-align: center; }
		.dashed{ height: 100%;border-left: 1px #fff dashed; }
		.tips{ background: url(../../static/wx.png) no-repeat;background-size: 24rpx 24rpx;background-position: 30rpx center;color: $font-color-light;font-size: 24upx;line-height: 60upx;padding-left: 60upx; }
		.circle{ background: #f3f3f3;border-radius: 100px;bottom: -10upx;height: 20upx;left: -6upx;position: absolute;width: 20upx;z-index: 10;
			&.r{ left: auto;right: -6upx;}
		}
	}
</style>
